package com.xunker.appointment.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/(api|P2P)/.*")))//显示api或P2P路径下的页面
                .build();
    }

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("网站-Api文档")
                .description("描述了微服务接口的定义")
                .version("1.0")
                .contact(new Contact("xunker", "http://xunker.com", "2296602826@qq.com"))
                .build();
    }

    @Bean
    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))//显示admin路径下的页面
                .build();
    }

    private ApiInfo adminInfo() {
        return new ApiInfoBuilder()
                .title("网站-Api文档")
                .description("描述了微服务接口的定义")
                .version("1.0")
                .contact(new Contact("xunker", "http://xunker.com", "2296602826@qq.com"))
                .build();
    }
}
